/**
 * Created with Vim7.3 Mac
 * @fileOverview :
 * @author : Lyle lylechen2014@gmail.com
 * @since : 2016-06-02 14:22:18
 * @filename : src/index.js
 * @version :
 * @description :
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
} from 'react-native';

import Register from './register';
import Login from './login';

class Index extends Component {

    constructor(props) {
        super(props);
        this.state = {};
        this.getFixedData();
    }

    render() {
        return (
            <View style={styles.container}>

                <Image style={styles.imgbg} resizeMode={Image.resizeMode.cover} source={require('../img/loading.jpg') }>

                    <View style={styles.box}>

                        <View style={styles.logoIndex}>
                            <Image style={styles.logo} resizeMode={Image.resizeMode.contain} source={require('../img/logo.png') }></Image>
                        </View>

                        <View style={styles.desIndex}>
                            <Text style={styles.desText} suppressHighlighting={true}  >
                                {Lang.index_des}
                            </Text>
                        </View>

                        <View style={styles.buttonIndex}>
                            <Text style={styles.signup} onPress={()=>this.gotoSignup()} suppressHighlighting={true}  >
                                {Lang.index_reg}
                            </Text>
                            <Text style={styles.login} onPress={() =>this.gotoLogin()}>
                                {Lang.index_login}
                            </Text>
                        </View>

                    </View>

                </Image>
            </View>
        );
    }

    getFixedData() {
        let tthis = this;
        Share.getStorage('local_gender',function(bool){
              if (!bool) {
                Share.fetchMain({
                     url : 'get_profile_options',
                     callback : function(data) {
                          if (data.results) {
                              let arr = Share.objToStorageArr(data.data);
                              arr = Share.storagePrefix(arr,'local_');
                              Share.setMultiStorage(arr,function(bool){
                                    if (bool) {
                                        Share.getAllStorage(function(bool,all){
                                          global.Store = all;
                                        });
                                    }
                              }); 
                          }
                     }
                  })
              } else {
                Share.getAllStorage(function(bool,all){
                  global.Store = all;
                });
              }
        })
    }

    gotoSignup() {
        Utils.navJumpTo(this.props.navigator,{name:"Register",component:Register,title:'Register'});
    }

    gotoLogin() {
        Utils.navJumpTo(this.props.navigator,{name: "Login", component: Login, title: 'Log In'});
    }
}

const styles = StyleSheet.create(Css.IndexStyle);

export default Index;

